<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('集中器和热关联列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="baseConcentratorData-form">
                <input type="hidden" id="concentratorId" name="concentratorId" th:value="${concentratorId}">
                <div class="select-list">
                    <ul>
                        <li>
                            热表ID：<input type="text" name="calorimeterId"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="selectMeter()">
                <i class="fa fa-plus"></i> 添加热表
            </a>
            <a class="btn btn-danger multiple disabled" onclick="cancelAuthMeterAll()">
                <i class="fa fa-remove"></i> 批量取消授权
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "module/concentrator/data/authMeter";
    $(function() {
        var options = {
            url: prefix + "/allocatedList",
            queryParams: queryParams,
            sortName: "calorimeterId",
            sortOrder: "asc",
            modalName: "热表",
            columns: [{
                checkbox: true
            },
                {
                    field: 'calorimeterId',
                    title: '热表ID'

                },
                {
                    field: 'calorimeterType.typeName',
                    title: '热表型号'
                },
                {
                    field: 'installTime',
                    title: '安装时间'
                },
                {
                    field: 'installAddress',
                    title: '安装地址'
                },
                {
                    field: 'installUser',
                    title: '安装人'
                },
                {
                    field: 'factory.factoryName',
                    title: '厂商名称'
                },
                {
                    field: 'factory.factoryCode',
                    title: '厂商代码'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancelAuthMeter(\'' + row.calorimeterId + '\')"><i class="fa fa-remove"></i>取消授权</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.concentratorId = $("#concentratorId").val();
        return search;
    }

    /* 分配热表-选择热表 */
    function selectMeter() {
        var url = prefix + '/selectMeter/' + $("#concentratorId").val();
        $.modal.openFull("选择热表", url);
    }

    /* 分配热表-批量取消授权 */
    function cancelAuthMeterAll(calorimeterId) {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要取消关联选中的" + rows.length + "条数据吗?", function() {
            var data = { "concentratorId": $("#concentratorId").val(), "calorimeterIds": rows.join() };
            $.operate.submit(prefix + "/cancelAll", "post", "json", data);
        });
    }

    /* 分配热表-取消授权 */
    function cancelAuthMeter(calorimeterId) {
        $.modal.confirm("确认要取消关联该热表吗？", function() {
            $.operate.post(prefix + "/cancel", { "concentratorId": $("#concentratorId").val(), "calorimeterId": calorimeterId });
        })
    }
</script>
</body>
</html>